package com.example.actearly_revised;

import java.util.Calendar;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.EditText;

@TargetApi(11)
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {

	//final Calendar;
	int year;
	int month;
	int day;
	EditText text;
	DatePicker newPick;
	Boolean showing;
	public Boolean getShowing() {
		return showing;
	}

	@SuppressLint("NewApi")
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the current date as the default date in the picker
		showing = false;
		final Calendar c = Calendar.getInstance();
		year = c.get(Calendar.YEAR);
		month = c.get(Calendar.MONTH);
		day = c.get(Calendar.DAY_OF_MONTH);

		// Create a new instance of DatePickerDialog and return it
		return new DatePickerDialog(getActivity(), this, year, month, day);
	}
	
	public String getDate(){
		//newPick = new DatePicker(getActivity());
		//month = newPick.getMonth();
		//year = newPick.getYear();
		//day = newPick.getDayOfMonth();
		String monthS = Integer.toString(month);
		String dayS  = Integer.toString(day);
		String yearS = Integer.toString(year);
		if (monthS.length()==1)
				{monthS="0"+monthS;
				}
		
		if (dayS.length()==1)
		{
			dayS="0"+dayS;
		}
		System.out.println(monthS+dayS+yearS);
		String bdate=monthS+"/"+ dayS+"/"+yearS;
		return bdate;
		
	}
	
	public EditText getEdit(EditText input){
		text = input;
		return input;
		
	}
	
@Override
public void onStop(){
	super.onStop();
	System.out.println("SDFADAFDSFADS");
	
	text.setText(getDate());
	showing = true;
}

	public void onDateSet(DatePicker view, int year, int month, int day) {
	System.out.println("sa");
	this.year = year;
	if(month < 12){
	this.month = month +1;
	}
	else{
		month = 1;
	}
	this.day = day;
	System.out.println("" + year +" " +month + " " + day);
		// Do something with the date chosen by the user
	}
}